package cn.bingo.yunsj.service;

import cn.bingo.yunsj.common.StateCode;
import cn.bingo.yunsj.common.exception.EmException;
import cn.bingo.yunsj.common.exception.OwnException;
import cn.bingo.yunsj.mail.model.ConfigProperties;
import cn.bingo.yunsj.model.HrUserSimpleInfo;
import cn.bingo.yunsj.common.result.Response;
import cn.bingo.yunsj.utils.HttpClientUtils;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Service
public class DataCacheService {

    // 需要存放邮箱跟用户名对接
    private static Map<String,String> user_mail = new HashMap<>();

    // 需要部门跟部门所有邮箱
    private static Map<String,String> dept_mail = new HashMap<>();

    // 所有人 所有人邮箱
    private static Map<String,String> all_mail = new HashMap<>();

    // 用户名跟入职年限对接
    private static Map<String,String> user_join = new HashMap<>();

    // 用户名跟离职年限对接
    private static Map<String,String> user_dim = new HashMap<>();

    // 用户名跟计划转正年限
    private static Map<String,String> user_plan = new HashMap<>();

    // 将数据加载到全局缓存
    public Response getAll(){
        HttpClientUtils<HrUserSimpleInfo> httpClientUtils = new HttpClientUtils<>();
        HrUserSimpleInfo hrUserSimpleInfo = new HrUserSimpleInfo();
        ConfigProperties configProperties = new ConfigProperties();
        try {
            hrUserSimpleInfo = httpClientUtils.SimpleInfo(configProperties.getHrUserSimpleInfo(),hrUserSimpleInfo);
        } catch (IOException e) {
            throw new OwnException(EmException.SYSTEM_EXCPTION,e.getMessage());
        }
        hrUserSimpleInfo.getResult().forEach(e->{
            user_mail.put(e.getUserName(),e.getExEmail());
        });
        return new Response(StateCode.FIND_SUCCESS);
    }

    public static Map<String, String> getUser_mail() {
        return user_mail;
    }

    public static void setUser_mail(Map<String, String> user_mail) {
        DataCacheService.user_mail = user_mail;
    }
}
